package com.smart.stock.common.util.spring;

import org.apache.commons.lang.StringUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.mongodb.core.mapping.Document;

public class EntityUtil {

    public static <T> String getEntityNameByCode(Class<T> entityClass, String code){
        Document document = AnnotationUtils.getAnnotation(entityClass, Document.class);
        String collection = document.collection();
        if (StringUtils.isNotBlank(code)) {
            collection = collection + "_" +code;
        }
        return collection;
    }

    public static <T> String getEntityNameByDate(Class<T> entityClass, String tradeDate){
        Document document = AnnotationUtils.getAnnotation(entityClass, Document.class);
        String collection = document.collection();
        if (StringUtils.isNotBlank(tradeDate)) {
            collection = collection + "_" +tradeDate;
        }
        return collection;
    }
}
